{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Export your design to GDS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For convenience, let's begin by enabling [automatic reloading of modules](https://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html?highlight=autoreload) when they change."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Will export_to_gds() add to my GDS file?   \n",
    "Most likely, yes!\n",
    "\n",
    "The cells below describe what is in an exported gds file. Geometries that an user wants to add for a component, can be put on a layer chosen by user. What export_to_gds does in the background is not finalized and will most likely be changed, based on a format, that is usable by multiple types of users.  Layers represent manufacturing intention, thus proprietary information, which cannot be published outside scientific papers or fab-customer relationships. While on our roadmap, we have the enablement, of a techfile-driven setup for layers. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Import Qiskit Metal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import qiskit_metal as metal\n",
    "from qiskit_metal import designs, draw\n",
    "from qiskit_metal import MetalGUI, Dict, Headings\n",
    "from qiskit_metal.qlibrary.qubits.transmon_pocket import TransmonPocket\n",
    "from qiskit_metal.qlibrary.qubits.transmon_cross import TransmonCross"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "design = designs.DesignPlanar()\n",
    "gui = MetalGUI(design)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "design.overwrite_enabled = True\n",
    "design.delete_all_components() \n",
    "gui.rebuild() # refresh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Headings.h1('Populate QDesign to demonstrate exporting to GDS format.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.qubits.transmon_pocket import TransmonPocket\n",
    "\n",
    "# Allow running the same cell here multiple times to overwrite changes.\n",
    "design.overwrite_enabled = True\n",
    "\n",
    "## Custom options for all the transmons.\n",
    "options = dict(\n",
    "    # Some options we want to modify from the defaults.\n",
    "    # (see below for defaults)\n",
    "    pad_gap = '80 um',\n",
    "    pad_width = '425 um', \n",
    "    pocket_height = '650um',\n",
    "    # Adding 4 connectors (see below for defaults)\n",
    "    connection_pads=dict( \n",
    "        a = dict(loc_W=+1,loc_H=+1), \n",
    "        b = dict(loc_W=-1,loc_H=+1, pad_height='30um'),\n",
    "        c = dict(loc_W=+1,loc_H=-1, pad_width='200um'),\n",
    "        d = dict(loc_W=-1,loc_H=-1, pad_height='50um')\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Note repeated from \"Introduction to QRenderers.ipynb\":  \n",
    "The cell name denoted by, \"gds_cell_name\" will be the selected cell   \n",
    "from design.renderers.gds.options['path_filename']   \n",
    "when design.renderers.gds.export_to_gds() is executed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## Create 4 TransmonPockets\n",
    "\n",
    "# For variety and demonstartion, use different gds_cell_names.\n",
    "q1 = TransmonPocket(design, 'Q1', options = dict(\n",
    "    pos_x='+2.55mm', pos_y='+0.0mm', gds_cell_name='FakeJunction_02', **options))\n",
    "q2 = TransmonPocket(design, 'Q2', options = dict(\n",
    "    pos_x='+0.0mm', pos_y='-0.9mm', orientation = '90', gds_cell_name='FakeJunction_01', **options))\n",
    "q3 = TransmonPocket(design, 'Q3', options = dict(\n",
    "    pos_x='-2.55mm', pos_y='+0.0mm', gds_cell_name='FakeJunction_01',**options))\n",
    "q4 = TransmonPocket(design, 'Q4', options = dict(\n",
    "    pos_x='+0.0mm', pos_y='+0.9mm', orientation = '90', gds_cell_name='my_other_junction', **options))\n",
    "\n",
    "## Rebuild the design\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Connecting QPins with coplanar waveguides (CPWs) as described in earlier notebooks."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.tlines.meandered import RouteMeander\n",
    "RouteMeander.get_template_options(design)\n",
    "\n",
    "options = Dict(\n",
    "    meander=Dict(\n",
    "        lead_start='0.1mm',\n",
    "        lead_end='0.1mm',\n",
    "        asymmetry='0 um')\n",
    ")\n",
    "\n",
    "\n",
    "def connect(component_name: str, component1: str, pin1: str, component2: str, pin2: str,\n",
    "            length: str, asymmetry='0 um', flip=False, fillet='50um'):\n",
    "    \"\"\"Connect two pins with a CPW.\"\"\"\n",
    "    myoptions = Dict(\n",
    "        fillet=fillet,\n",
    "        pin_inputs=Dict(\n",
    "            start_pin=Dict(\n",
    "                component=component1,\n",
    "                pin=pin1),\n",
    "            end_pin=Dict(\n",
    "                component=component2,\n",
    "                pin=pin2)),\n",
    "        lead=Dict(\n",
    "            start_straight='0.13mm',\n",
    "            end_straight='0.13mm'\n",
    "        ),\n",
    "        total_length=length)\n",
    "    myoptions.update(options)\n",
    "    myoptions.meander.asymmetry = asymmetry\n",
    "    myoptions.meander.lead_direction_inverted = 'true' if flip else 'false'\n",
    "    return RouteMeander(design, component_name, myoptions)\n",
    "\n",
    "\n",
    "asym = 90\n",
    "\n",
    "# For variety in output, use different fillet values.\n",
    "cpw1 = connect('cpw1', 'Q1', 'd', 'Q2', 'c', '5.7 mm', f'+{asym}um', fillet='25um')\n",
    "cpw2 = connect('cpw2', 'Q3', 'c', 'Q2', 'a', '5.4 mm', f'-{asym}um', flip=True, fillet='100um')\n",
    "cpw3 = connect('cpw3', 'Q3', 'a', 'Q4', 'b', '5.3 mm', f'+{asym}um', fillet='75um')\n",
    "cpw4 = connect('cpw4', 'Q1', 'b', 'Q4', 'd', '5.5 mm', f'-{asym}um', flip=True)\n",
    "\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gui.screenshot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Headings.h1('Exporting to a GDS file.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "#QDesign registers GDS renderer during init of QDesign.\n",
    "a_gds = design.renderers.gds\n",
    "# An alternate way to invoke gds commands without using a_gds:\n",
    "# design.renderers.gds.export_to_gds()\n",
    "\n",
    "#Show the options for GDS\n",
    "a_gds.options"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Will export_to_gds() add datatype for Polygon and Flexpath to my GDS file. \n",
    "Yes.  If you see a datatype being added to your positive mask, datatype=10 means a Polygon was added to the layer, datatype=11 means Flexpath was added to the layer.   However, `for each layer` that has a negative mask, due to boolean subtract command done by export_to_gds, the 10 and 11 datatypes will not be in the gds file.\n",
    "\n",
    "For positive mask, datatype=0 is for the ground plane. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##  To make `junction table` work correctly, GDS Renderer needs a correct path to a gds file, which has cells.  \n",
    "Each cell is a junction, to be placed, in a Transmon.  A sample gds file is provided in directory `qiskit_metal/tutorials/resources`.\n",
    "There are three cells with names \"Fake_Junction_01\", \"Fake_Junction_01\", and \"my_other_junction\".\n",
    "The default name used by GDS Render is \"my_other_junction\".  If you want to customize and select a junction, through the QComponent's options, you can pass it when a qcomponent is being added to QDesign. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## If your added junctions to a qcomponent.\n",
    "\n",
    "The junctions are imported from file at gds.options.path_filename.  The cell from path_filename which is denoted by TransmonPocket.options.gds_cell_name is imported and placed at location determined by the qcomponent developer.  The method export_to_gds will place the imported cell at the same layers which are identified in the file at gds.options.path_filename."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a_gds.options['path_filename'] = '../resources/Fake_Junctions.GDS'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Do you want GDS Renderer to fix any short-segments in your QDesign when using fillet?'\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#If you have a fillet_value and there are LineSegments that are shorter than 2*fillet_value, \n",
    "#When true, the short segments will not be fillet'd. \n",
    "a_gds.options['short_segments_to_not_fillet'] = 'False'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "scale_fillet = 2.0\n",
    "a_gds.options['check_short_segments_by_scaling_fillet'] = scale_fillet"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## What criteria will be used for identifying a short segment?\n",
    "If a segment is smaller than (fillet length *  scale_fillet)\n",
    "\n",
    "## What if a segment of LineString has few short segments?  \n",
    "If option 'short_segments_to_not_fillet' == 'True', QGDSRenderer will\n",
    "break the LineString into shorter Linestrings to make smaller LineStrings that will be \n",
    "either fillet'd or not, based on if the segment is short."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#If you want to have the short segments not be fillet'd.\n",
    "a_gds.options['short_segments_to_not_fillet'] = 'True'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Export to a GDS formatted file for all components in design.\n",
    "#def export_to_gds(self, file_name: str, highlight_qcomponents: list = []) -> int:\n",
    "\n",
    "a_gds.export_to_gds('GDS QRenderer Notebook.gds')\n",
    "# You can also specify a different path. Example:\n",
    "#   a_gds.export_to_gds(\"../../../gds-files/GDS QRenderer Notebook.gds\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Export a GDS file which contains only few components.\n",
    "\n",
    "# You will probably want to put the exported file in a specific directory.  \n",
    "# Please give the full path for output. \n",
    "a_gds.export_to_gds(\"four_qcomponents.gds\",\n",
    "                           highlight_qcomponents=['cpw1', 'cpw4', 'Q1', 'Q3'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Export a GDS file using explicit path and cpw1.name vs typing string.\n",
    "# You will probably want to put the exported file in a specific directory.  \n",
    "# Please give the full path for output. \n",
    "a_gds.export_to_gds(\"four_same_qcomponents.gds\",\n",
    "                           highlight_qcomponents=[cpw1.name, 'cpw4', q1.name, 'Q3'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Headings.h1('QUESTION:  Where is the geometry of a QComponent placed?')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Answer:  QGeometry tables!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is better explained in folder \"2 Front End User/2.4 QRenderer Introduction\" in notebook, \"QRenderer Introduction \"."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Headings.h1('What does GDS do with \"junction\" table?')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The junction table is handled differently by each QRenderer.\n",
    "\n",
    "GDS QRenderer gets a cell, with the name, equal to \"gds_cell_name\" and places the cell into the QDesign before exporting the entire QDesign to GDS. In file: `a_gds.options['path_filename'] = '../resources/Fake_Junctions.GDS'`, the gds_cell_name is searched.  The cell is placed into QDesign using LINESTRING and width information.\n",
    "\n",
    "The cell within \"path_filename\", should be \"x-axis\" aligned and then GDS rotates based on LineString.  The LineString should be two vertexes and it denotes two things.\n",
    "1. The midpoint of segment is the center of cell. \n",
    "2. The angle made by (second tuple - fist tuple), for delta y/ delta x, is used to rotate the cell. \n",
    "\n",
    "When the cell from default_options.path_filename does not fit the width of LineString,\n",
    "- QGDSRender will create two pads and add to cell, which is denoted in junction table, to fill the width of LineString. The length of the additional pads is the value of \"width\" from the junction table. \n",
    "- The option `a_gds.options[\"junction_pad_overlap\"]='5um'` is the amount the new pads will overlap the cell. The final width of the cell plus two pads is equal to the magnitude of LineString. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# View every entry in junction table.\n",
    "design.qgeometry.tables['junction']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# View the juction table for component \"q1\". \n",
    "\n",
    "q1.qgeometry_table('junction')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Geometric boundary of a QComponent?\n",
    "How to obtain the boundary box of the geometry, for example: `q1.qgeometry_bounds()`.  \n",
    "Explained in in folder \"2 Front End User/2.4 QRenderer Introduction\" in notebook, \"QRenderer Introduction \"."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#The current value of all the options for GDS QRenderer.\n",
    "a_gds.options"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Number of vertices for linestrings.\n",
    "The option max_points has default of 199.  You can set it to a number no higher than 8191."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### For demo, set max_points to 8191 and look at the GDS output.\n",
    "a_gds.options['max_points'] = '8191'\n",
    "a_gds.export_to_gds('GDS QRenderer Notebook maxpoints8191.gds')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Changing options 'precision' vs 'tolerance' ratio can impact how fillet will look.\n",
    "\n",
    "The below numbers are used to create a gdspy.FlexPath when \n",
    "there is a fillet value in QGeometry table.\n",
    "\n",
    "bend_radius – Bend radii for each path when corners is ‘circular bend’. \n",
    "It has no effect for other corner types.  QGDSRender uses 'circular bend' as a default for corners.\n",
    "The fillet value used here.\n",
    "\n",
    "Ensure that tolerance > precision.\n",
    "\n",
    "tolerance (number) – Tolerance used to draw the paths and calculate joins.\n",
    "\n",
    "precision (number) – Precision for rounding the coordinates of vertices when fracturing the final polygonal boundary.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Restore previous example.\n",
    "a_gds.options['max_points'] = '199'\n",
    "\n",
    "# For Demo, change tolerance value.\n",
    "a_gds.options['tolerance'] = '0.01'\n",
    "# This exported file will not look as desired.\n",
    "a_gds.export_to_gds('GDS QRenderer Notebook change tolerance.gds')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#change it back to was it was.\n",
    "a_gds.options['tolerance'] = '0.00001'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "Headings.h1('Layer numbers: cheese and mask')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## What can I control by layer number?  \n",
    "\n",
    "* positive mask\n",
    "* negative mask\n",
    "* cheese\n",
    "* no_cheese\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## If you wanted cheese or no_cheese in the GDS file.\n",
    "\n",
    "\n",
    "The reason you choose to use cheesing is up to the developer.   There are considerations for both manufacturing and EM design.  This refers to the holes in the output GDS ground plane (cheese = holes). From an EM stand-point https://www.degruyter.com/document/doi/10.1515/psr-2017-8000/html.\n",
    "\n",
    "Cheesing refers to the holes added to the chip. The “cheese” output will correspond to the mask (positive or negative) selected.  Both cheese and no_cheese output can be generated for any layer.  You can choose to add the no_cheese to the exported GDS file; adding no_cheese information in GDS file, is just to show the intermediate step.\n",
    "\n",
    "In the cheese dict, edge_nocheese option denotes a buffer around the perimeter of the chip.  You can identify which layer has the cheesing by using the key view_in_file.  To identify a datatype to store the geometry for cheesing, edit the key named datatype. \n",
    "\n",
    "The option no_cheese can be thought of as a “keep-out” region for cheesing.  Based on the components on the chip, a no-cheese region is determined.  The no_cheese region is created by adding a buffer around all the components.   In no_cheese dict, there is a key called buffer, that denotes the size around all the components for no_cheese.  Even if view_in_file may be True for cheese dict, user can make it false for no_cheese dict.  If the user wants to view the no_cheese region in the GDS output, keep it as True for each layer you are interested it.  \n",
    "\n",
    "The location of cheesing is determined by\n",
    "1. generating a grid of holes for the size of chip\n",
    "2. subtract the no_cheese region\n",
    "3. subtract the edge_nocheese region\n",
    "\n",
    "\n",
    "The method export_to_gds, uses the datatype in cheese dict, default is 100, and no_cheese dict, default is 99; then uses few extra datatypes by adding one or two.   The extra datatypes are to show some intermediate steps.  If you choose to view_in_file, then you will see cheese or no-cheese in the gds file.  \n",
    "\n",
    "TOP_chipname_layernumber_one_hole is a cell with just one hole.  The rest of the holes are made as a reference from the one hole.  The hole is placed with datatype_cheese+2.  This is expected to change when we agree to some convention. \n",
    "\n",
    "TOP_chipname_layernumber_NoCheese_datatype is a cell that holds the “keep-out” region for cheesing.  \n",
    "\n",
    "TOP_chipname_layernumber_Cheese_datatype is a cell that holds the cheesing region.  \n",
    "\n",
    "TOP_chipname_layernumber holds the geometry taken from Metal GUI.   \n",
    "\n",
    "\n",
    "\n",
    "TOP_chipname_layernumber_Cheese_diff is a cell that holds the difference between grid of holes on chip, minus the no_cheese region.  It is placed in datatype_cheese+1.  This is expected to change when we agree to some convention. \n",
    "\n",
    "`For negative mask`:\n",
    "TOP_chipname_layernumber_Cheese_diff is placed under TOP_chipname_layernumber.  \n",
    "\n",
    "\n",
    "`For positive mask`:\n",
    "TOP_chipname_layernumber_Cheese_diff is subtracted from ground and placed under TOP_chipname_layernumber. \n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Changing Cheesing options\n",
    "There are two dicts in default_options for cheesing.  One for selecting the no_cheese (keep-out region) for cheesing, the other for cheesing.  Use them to determine if you would like the cheesing cell and the no_cheese cell to be added to the GDS file.\n",
    "\n",
    "To create the no-cheese region, we take the existing components and add a buffer around the perimeter.  The size of the buffer is an option.  \n",
    "\n",
    "The output of the cells can be placed with a data type.  The user can select a different data type for both the no-cheese region and the cheese region.\n",
    "\n",
    "Regarding the cheese option, there is room for expansion, presently, the shape that available for a hole is a shape=0, which is a square.  \n",
    "\n",
    "The present placement of holes allows the user to apply edge_nocheese to the perimeter of the chip.  This allows the user to place holes at a perimeter smaller than the chip size.   Then a grid of holes is made using delta_x and delta_y. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a_gds.options.no_cheese"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a_gds.options.cheese"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There is a dict option called view_in_file that denotes if the cells are added to GDS file.  The first sub-option is the chip name, the second sub-option is layer number, the third sub-option is  bool True/False. \n",
    "\n",
    "In our example, the chip is 'main' and the layer is 1.  We allow for expansion for multiple chips, and multiple ground layers. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a_gds.options['cheese']['view_in_file']['main'][1] = True\n",
    "a_gds.options['no_cheese']['view_in_file']['main'][1] = True\n",
    "a_gds.export_to_gds(\"GDS QRender_cheese_keepout.gds\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a_gds.options['cheese']['view_in_file']['main'][1] = True\n",
    "a_gds.options['no_cheese']['view_in_file']['main'][1] = False\n",
    "a_gds.export_to_gds(\"GDS QRender_cheese_only.gds\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#For example, just move the cpws to layer=14. \n",
    "cpw1.options.layer = 14\n",
    "cpw2.options.layer = 14\n",
    "cpw3.options.layer = 14\n",
    "cpw4.options.layer = 14\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gui.rebuild()\n",
    "\n",
    "# Get a list of all the qcomponents in QDesign and then zoom on them.\n",
    "all_component_names = design.components.keys()\n",
    "gui.zoom_on_components(all_component_names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Turn on/off keep-out and cheesing.\n",
    "a_gds.options['cheese']['view_in_file']['main'][1] = True\n",
    "a_gds.options['no_cheese']['view_in_file']['main'][1] = True\n",
    "a_gds.options['cheese']['view_in_file']['main'][14] = True\n",
    "a_gds.options['no_cheese']['view_in_file']['main'][14] = True\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## If you want a positive and/or negative masks.  \n",
    "\n",
    "User can request a positive or negative mask by chip-name and layer-number.  The default is to use a positive mask.  If user wants to use a negative mask, then just identify the layers that should be a negative mask.  The user is allowed to mix the output per chip, per layer. Particularly, a chip can have both positive and negative masks; the granularity is by layer.  This is exemplified in this notebook by editing option “negative_mask”. This feature was implemented for, potential use, for \"flip-chip\".\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Export GDS file with negative masks for layers 1 and 14.\n",
    "a_gds.options['negative_mask'] = Dict(main=[1, 14])\n",
    "a_gds.export_to_gds('GDS QRenderer Notebook_neg_mask_for_layer_1_14.gds')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# Export GDS files with positive mask for layer 1 and negative mask for layer 14. \n",
    "a_gds.options['negative_mask'] = Dict(main=[14])\n",
    "a_gds.export_to_gds('GDS QRenderer Notebook_neg_mask_for_layer_14.gds')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Headings.h1('Fabrication')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There is no universally accepted method to prepare for fabrication of a chip.  If this flag is True, cells created as part of intermittent steps would not be in the gds file. For example cells with names similar to “TOP_main_1_NoCheese_99” , “TOP_main_1_one_hole” and  “ground_main_1”."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#By default, the fabrication flag is False.  \n",
    "a_gds.options['fabricate'] = 'True'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Export GDS files with positive mask for layer 1 and negative mask for layer 14 with fabricate flag as True. \n",
    "a_gds.options['negative_mask'] = Dict(main=[14])\n",
    "a_gds.export_to_gds('GDS QRenderer Notebook_neg_mask_for_layer_14_fabricate.gds')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##  Qiskit Metal Version"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "metal.about();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# If you would like, close the gui \n",
    "gui.main_window.close()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
